<div>
	<ul class="nav pull-left">
		<li class="pull-left">
			<select id="field" style="width:auto" onchange="changeCondition()" name="field">
				<option class="word" value="">{:L('PLEASE_SELECT_A_FILTER_CONDITION')}</option>
				<option class="word" value="business.name">{:L('BUSINESS_NAME')}</option>
				<option class="business_status" value="business.status_id">{:L('BUSINESS_OPPORTUNITIES_PHASE')}</option>
				<option class="role" value="business.owner_role_id">{:L('PRINCIPAL')}</option>
				<option class="customer" value="business.customer_id">{:L('CUSTOMER')}</option>
				<option class="number" value="business.total_price">{:L('THE_TOTAL_AMOUNT_OF')}</option>
			</select>&nbsp;&nbsp;
		</li>
		<li id="conditionContent" class="pull-left">
			<select id="condition" style="width:auto" name="condition" onchange="changeSearch()">
				<option value="contains">{:L('INCLUDE')}</option>
				<option value="is">{:L('YES')}</option>								
				<option value="start_with">{:L('BEGINNING_CHARACTER')}</option>
				<option value="end_with">{:L('TERMINATION_CHARACTER')}</option>
				<option value="is_empty">{:L('MANDATORY')}</option>
			</select>&nbsp;&nbsp;
		</li>
		<li id="searchContent" class="pull-left">
			<input id="search" type="text" class="input-medium search-query" name="search"/>&nbsp;&nbsp;
		</li>
		<li class="pull-left">
			<button type="submit" class="btn" onclick="d_changeCondition(0)">{:L('SEARCH')}</button>
		</li>
		&nbsp;<a target="_blank" href="{:U('business/add')}">{:L('NEW_BUSINESS_OPPORTUNITIES')}</a>
	</ul>
</div>
<p>&nbsp;</p>
<empty name="businessList">
	<div class="alert">{:L('TEMPORARILY_NO_DATA')}</div>
<else/>
	<table class="table table-hover">
		<thead>
			<tr> 
				<th></th>
				<th>{:L('BUSINESS_OPPORTUNITY')}</th>
				<th>{:L('CUSTOMER')}</th>
				<th>{:L('LINKMAN')}</th>
				<th>{:L('AMOUNT')}</th>
				<if condition="C('ismobile') neq 1"><th>{:L('PHASE')}</th></if>		
			</tr>
		</thead>
		<tfoot id="footer">
			<tr>
				<if condition="C('ismobile') neq 1"><td colspan="6"><else /><td colspan="4"></if>
					<div class="row pagination">
						<div class="span2"><span id="count">{$count_num}</span> {:L('RECORDS')} <span id="p">1</span>/<span id="total_page">{$total}</span> {:L('PAGE')}</div>
						<div class="span4">
							<div><ul id="changepage">
								<li><span class='current'>{:L('FIRST_PAGE')}</span></li><li><span>« {:L('THE_PREVIOUS_PAGE')}</span></li>
								<if condition="1 lt $total">
									<li><a class="page" href="javascript:void(0)" rel="2">{:L('THE_NEXT_PAGE')} »</a></li>
								<else />
									<li><span>{:L('THE_NEXT_PAGE')} »</span></li>
								</if>
							</ul></div>
						</div>
					</div>
				</td>
			</tr>
		</tfoot>
		<tbody id="load" class="hide">
			<tr><td class="tdleft" <if condition="C('ismobile') neq 1">colspan="6"<else />colspan="4"</if> style=" height:300px;text-align:center"><img src="./Public/img/load.gif"></td></tr>
		</tbody>
		<tbody id="data">
			<volist name="businessList" id="vo">
				<tr>
					<td><input type="radio" name="business" value="{$vo.business_id}"/><input type="hidden" id="dialog_customer_id" value="{$vo.customer_id}"/><input type="hidden" id="dialog_contacts_id" value="{$vo.contacts_id}"/></td>
					<td>{$vo.name}</td>
					<td><a target="_blank" href="{:U('customer/view','id='.$vo['customer_id'])}">{$vo.customer_name}</a></td>
					<td><a target="_blank" href="{:U('contacts/view','id='.$vo['contacts_id'])}">{$vo.contacts_name}</a></td>
					<td><if condition="$vo['estimate_price'] gt 0">{$vo.estimate_price}</if></td>
					<if condition="C('ismobile') neq 1"><td>{$vo.status_name}</td></if>
				</tr>
			</volist>
		</tbody>
	</table>
</empty>
<script type="text/javascript">
	$('.page').click(function(){
		var a = $(this).attr('rel');
		d_changeCondition(a);
	});
	function d_changeCondition(p){
		$('#data').addClass('hide');
		$('#load').removeClass('hide');
		
		var field = $('#field').val();
		var condition = $('#condition').val();
		var search = encodeURI($("#search").val());
		var customer_link = "{:U('customer/view','id=')}";
		var contacts_link = "{:U('contacts/view','id=')}";
		$.ajax({
			type:'get',
			url:'index.php?m=business&a=changecontent&field='+field+'&search='+search+'&condition='+condition+'&p='+p,
			async:false,
			success:function(data){
				var temp = '';
				if(data.data.list != null){
					$.each(data.data.list, function(k, v){
						temp += '<tr><td><input type="radio" name="business" value="'+v.business_id+'"/><input type="hidden" id="dialog_customer_id" value="'+v.customer_id+'"/><input type="hidden" id="dialog_contacts_id" value="'+v.contacts_id+'"/></td><td>'+v.name+'</td><td><a target="_blank" href="'+customer_link+v.customer_id+'">'+v.customer_name+'</a></td><td><a target="_blank" href="'+contacts_link+v.contacts_id+'">'+v.contacts_name+'</a></td><td>'+v.estimate_price+'</td>';
						<if condition="C('ismobile') neq 1">
							temp+="<td>"+v.status_name+"</td>";
						</if>
						temp+='</tr>';
					});
					var changepage = "";
					if(data.data.p == 1){
						changepage = "<li><span class='current'>{:L('FIRST_PAGE')}</span></li><li><span>« {:L('THE_PREVIOUS_PAGE')} </span></li>";
						if(data.data.p < data.data.total){
							changepage += "<li><a class='page' href='javascript:void(0)' rel='"+(data.data.p+1)+"'>{:L('THE_NEXT_PAGE')} »</a></li>";
						}else{
							changepage += "<li><span>{:L('THE_NEXT_PAGE')} »</span></li>";
						}
					}else if(data.data.p == data.data.total){
						changepage = "<li><a class='page' href='javascript:void(0)' rel='1'>{:L('FIRST_PAGE')}</a></li><li><a class='page' href='javascript:void(0)' rel='"+(data.data.p-1)+"'>« {:L('THE_PREVIOUS_PAGE')}</a></li><li><span>{:L('THE_NEXT_PAGE')} »</span></li>";
					}else{
						changepage = "<li><a class='page' href='javascript:void(0)' rel='1'>{:L('FIRST_PAGE')}</a></li><li><a class='page' href='javascript:void(0)' rel='"+(data.data.p-1)+"'>« {:L('THE_PREVIOUS_PAGE')}</a></li><li><a class='page' href='javascript:void(0)' rel='"+(data.data.p+1)+"'>{:L('THE_NEXT_PAGE')} »</a></li>";
					}
					$('#p').html(data.data.p);
					$('#changepage').html(changepage);
					$('#count').html(data.data.count);
					$('#total_page').html(data.data.total);
					$('#data').html(temp);
					$('.page').click(function(){
						var a = $(this).attr('rel');
						d_changeCondition(a);
					});
				}else{
					$('#data').html('<tr><td colspan="4">{:L('DO_NOT_FIND_THE_RESULTS_YOU_WANT')}</tr>');
					$('#footer').addClass('hide');
				}
				$('#load').addClass('hide');
				$('#data').removeClass('hide');
			},
			dataType:'json'
		});		
	}
</script>



